<div id="title_right">
	<p id="title_right_left"></p>
	<div id="title_right_center">
		<p class="chu_title">HÓA ĐƠN</p>
	</div>
	<p id="title_right_right"></p>
</div>
<?php if($data){ 
//var_dump($data['cthd']);?>
<table class="table">
		<tr class="mau2">
			<td>Tên Khách Hàng</td>
			<td>Ngày Lập</td>
			<td>Người Lập</td>
			<td>Tình Trạng</td>
		</tr>		
		<tr> 
	<td >
				<?php
				if(is_array($data['listkh'])){
					foreach ($data['listkh'] as $item){
						if($item['MaKH']==$data['MaKH']){ 
							echo $item['TenKH'];
						}
					}
				}
				?> </td>
				<td><?php echo $data['NgayLap'];?> </td>
				<td><?php echo $data['NguoiLap'];?> </td>
				<td><?php if($data['TinhTrang']==0)
				echo "Chưa duyệt";
				else 
				echo "Đã duyệt";
				?></td>
</table>

<?php }
?>

<div id="title_right">
	<p id="title_right_left"></p>
	<div id="title_right_center">
		<p class="chu_title">CHI TIẾT HÓA ĐƠN</p>
	</div>
	<p id="title_right_right"></p>
</div>

<?php if($data) {?>
		<table class="table">
			<tr class="mau2"> 
				<td>Mặt Hàng</td>
				<td>Số lượng</td>
				<td>Đơn giá bán</td>
				<td>Thành tiền</td>
				<td>Sửa</td>
				<td>Xóa</td>
			</tr>
			
		<?php 
		$i=1;
		$tongtien=0;
		foreach ($data['cthd'] as $key => $value){
			if($i%2==0){
					echo "<tr class='mau'>";
				}else
				{
					echo "<tr>";
				}
?>
				<td>
					<?php 
						if(is_array($data['listmh'])){
							foreach ($data['listmh'] as $item){
								if($item['MaMH'] == $value['MaMH']){
									echo $item['TenMH'];
								}
							}
						}
					?>
				 </td>
				<td><?php echo $value['SoLuongBan'];?></td>
					<td><?php echo $value['DonGiaBan'];?></td>
					<td ><?php echo $value['ThanhTienBan'];?></td>
					<td><a href="admin.php?mod=editchitiethd&id=<?php echo $value['MaCT']; ?>"><img src="public/images/b_edit.png" /></a>
					<td><a href="admin.php?mod=del_cthoadon&id=<?php echo $value['MaCT']; ?>"><img src="public/images/b_drop.png" /></a>
			</tr>
			
		<?php
$i++;
		$tongtien += $value['ThanhTienBan']; } ?>
			<tr>
			<td colspan="3">Tổng tiền</td>
			<td><?php echo $tongtien;?></td>
			</tr>
			
			<tr>
			<td colspan="4"><button onclick="window.location.href='admin.php?mod=inhoadon&id=<?php echo $value['MaHD'];?>'"> In hóa đơn </button></td>
			</tr>
		</table>
		
	<?php } ?>
	
